<template>
    <a-modal :visible="visible" :width="1200" @ok="submitForm" @cancel="cancel">
        <a-form-model ref="form" :model="model" :rules="validatorRules">
            <a-row>
                <a-col :span="24">
                    <a-form-model-item label="每人每天限点一次/一份" :labelCol="labelCol" :wrapperCol="wrapperCol"
                        prop="isLimitOrder">
                        <a-radio-group v-model="model.isLimitOrder" button-style="solid">
                            <a-radio-button value="no"> 否 </a-radio-button>
                            <a-radio-button value="yes"> 是 </a-radio-button>
                        </a-radio-group>
                    </a-form-model-item>
                </a-col>
                <a-col :span="24">
                    <a-form-model-item label="启用黑名单" :labelCol="labelCol" :wrapperCol="wrapperCol"
                        prop="isOpenBlackPaper">
                        <a-radio-group v-model="model.isOpenBlackPaper" button-style="solid">
                            <a-radio-button value="no"> 否 </a-radio-button>
                            <a-radio-button value="yes"> 是 </a-radio-button>
                        </a-radio-group>
                    </a-form-model-item>
                </a-col>
                <a-col :span="24">
                    <a-form-model-item label="黑名单列表" :labelCol="labelCol" :wrapperCol="wrapperCol">
                        <a-button icon="plus" type="primary" @click="addList('blackPaper')">添加</a-button>
                        <div v-for="(item, index) in model.blackPaper" :key="index">
                            <a-input v-model="item.value" style="width: 90%;"></a-input>
                            <a-button icon="delete" style="margin-left:10px"
                                @click="del('blackPaper', index)"></a-button>
                        </div>
                    </a-form-model-item>
                </a-col>
                <a-col :span="24">
                    <a-form-model-item label="启用白名单" :labelCol="labelCol" :wrapperCol="wrapperCol"
                        prop="isOpenWhitePaper">
                        <a-radio-group v-model="model.isOpenWhitePaper" button-style="solid">
                            <a-radio-button value="no"> 否 </a-radio-button>
                            <a-radio-button value="yes"> 是 </a-radio-button>
                        </a-radio-group>
                    </a-form-model-item>
                </a-col>
                <a-col :span="24">
                    <a-form-model-item label="白名单列表" :labelCol="labelCol" :wrapperCol="wrapperCol">
                        <a-button icon="plus" type="primary" @click="addList('whitePaper')">添加</a-button>
                        <div v-for="(item, index) in model.whitePaper" :key="index">
                            <a-input v-model="item.value" style="width: 90%;"></a-input>
                            <a-button icon="delete" style="margin-left:10px"
                                @click="del('whitePaper', index)"></a-button>
                        </div>
                    </a-form-model-item>
                </a-col>
                <a-col :span="24">
                    <a-form-model-item label="售后通知联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol"
                        prop="isOpenWhitePaper">
                        <a-button icon="plus" type="primary" @click="addList('noticePhone')">添加</a-button>
                        <div v-for="(item, index) in model.noticePhone" :key="index">
                            <a-input v-model="item.value" style="width: 90%;"></a-input>
                            <a-button icon="delete" style="margin-left:10px"
                                @click="del('noticePhone', index)"></a-button>
                        </div>
                    </a-form-model-item>
                </a-col>
                <a-col :span="24">
                    <a-form-model-item label="售后手机号" :labelCol="labelCol" :wrapperCol="wrapperCol"
                        prop="isOpenWhitePaper">
                        <a-radio-group v-model="model.isSetPhone" button-style="solid">
                            <a-radio-button value="no"> 否 </a-radio-button>
                            <a-radio-button value="yes"> 是 </a-radio-button>
                        </a-radio-group>
                    </a-form-model-item>
                </a-col>
                <a-col :span="24">
                    <a-form-model-item label="是否启用个人订单菜品" :labelCol="labelCol" :wrapperCol="wrapperCol"
                        prop="isOpenPrivateOrder">
                        <a-radio-group v-model="model.isOpenPrivateOrder" button-style="solid">
                            <a-radio-button value="no"> 否 </a-radio-button>
                            <a-radio-button value="yes"> 是 </a-radio-button>
                        </a-radio-group>
                    </a-form-model-item>
                </a-col>
                <a-col :span="24">
                    <a-form-model-item label="是否启用个人点餐入口" :labelCol="labelCol" :wrapperCol="wrapperCol"
                        prop="isOpenPrivateOrderInlet">
                        <a-radio-group v-model="model.isOpenPrivateOrderInlet" button-style="solid">
                            <a-radio-button value="no"> 否 </a-radio-button>
                            <a-radio-button value="yes"> 是 </a-radio-button>
                        </a-radio-group>
                    </a-form-model-item>
                </a-col>
                <a-col :span="24">
                    <a-form-model-item label="多日期点餐" :labelCol="labelCol" :wrapperCol="wrapperCol"
                        prop="isMultipleDatesOrder">
                        <a-radio-group v-model="model.isMultipleDatesOrder" button-style="solid">
                            <a-radio-button value="no"> 否 </a-radio-button>
                            <a-radio-button value="yes"> 是 </a-radio-button>
                        </a-radio-group>
                    </a-form-model-item>
                </a-col>
                <a-col :span="24">
                    <a-form-model-item label="是否显示价格" :labelCol="labelCol" :wrapperCol="wrapperCol"
                        prop="isMultipleDatesOrder">
                        <a-radio-group v-model="model.isShowPrice" button-style="solid">
                            <a-radio-button value="no"> 否 </a-radio-button>
                            <a-radio-button value="yes"> 是 </a-radio-button>
                        </a-radio-group>
                    </a-form-model-item>
                </a-col>
                <!-- <a-col :span="24">
                    <a-form-model-item label="自动创建昨天菜单" :labelCol="labelCol" :wrapperCol="wrapperCol"
                        prop="autoCreateMenuFlag">
                        <a-radio-group v-model="model.autoCreateMenuFlag" button-style="solid">
                            <a-radio-button value="no"> no </a-radio-button>
                            <a-radio-button value="yes"> yes </a-radio-button>
                        </a-radio-group>
                    </a-form-model-item>
                </a-col>
                <a-col :span="24">
                    <a-form-model-item label="时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="selectDepartmentFlag">
                        <j-date placeholder="请选择时间" v-model="model.time" style="width: 90%" />
                    </a-form-model-item>
                </a-col> -->
                <a-col :span="24">
                    <a-form-model-item label="是否实名登录" :labelCol="labelCol" :wrapperCol="wrapperCol"
                        prop="realNameLogin">
                        <a-radio-group v-model="model.realNameLogin" button-style="solid">
                            <a-radio-button value="0"> 否 </a-radio-button>
                            <a-radio-button value="1"> 是 </a-radio-button>
                        </a-radio-group>
                    </a-form-model-item>
                </a-col>
                <a-col :span="24">
                    <a-form-model-item label="是否启用个人支付" :labelCol="labelCol" :wrapperCol="wrapperCol">
                        <a-radio-group v-model="model.isOpenPersonalPay" button-style="solid">
                            <a-radio-button value="no"> 否 </a-radio-button>
                            <a-radio-button value="yes"> 是 </a-radio-button>
                        </a-radio-group>
                    </a-form-model-item>
                </a-col>
                <a-col :span="24">
                    <a-form-model-item label="企业每天补贴金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
                        <a-input v-model="model.subsidyAmount" style="width: 90%;"></a-input>
                    </a-form-model-item>
                </a-col>
            </a-row>
        </a-form-model>
    </a-modal>
</template>

<script>
import { postAction } from '../../../../api/manage';
export default {
    name: 'AntDesignVueJeecgSet',

    data() {
        return {
            visible: false,
            model: {
                blackPaper: [],
                whitePaper: [],
                noticePhone: []
            },
            labelCol: {
                xs: { span: 24 },
                sm: { span: 5 },
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 16 },
            },
            validatorRules: {
                isLimitOrder: [{ required: true, message: '请选择是否开启每人每天限点一次/一份!' }],
                isOpenBlackPaper: [{ required: true, message: '请选择是否启用黑名单!' }],
                isOpenWhitePaper: [{ required: true, message: '请选择是否启用白名单!' }],
                isOpenPrivateOrder: [{ required: true, message: '请选择是否启用个人订单菜品!' }],
                isOpenPrivateOrderInlet: [{ required: true, message: '请选择是否启用个人点餐入口!' }],
                autoCreateMenuFlag: [{ required: true, message: '请选择是否自动创建昨天菜单!' }],
            },

            companyInfo: ''
        };
    },

    mounted() {

    },

    methods: {
        show(record) {
            this.visible = true;
            this.companyInfo = record;
            this.model = { ...JSON.parse(JSON.stringify(record)) };
            console.log('this.model', this.model);
            let tempBlackpaer = [];
            let tempNoticePhone = [];
            let tempWhitePaper = [];
            if (this.model.blackPaper) {
                this.model.blackPaper.split(',').forEach(item => {
                    tempBlackpaer.push({ value: item })
                })
            }
            if (this.model.whitePaper) {
                this.model.whitePaper.split(',').forEach(item => {
                    tempWhitePaper.push({ value: item })
                })
            }
            if (this.model.noticePhone) {
                this.model.noticePhone.split(',').forEach(item => {
                    tempNoticePhone.push({ value: item })
                })
            }
            this.model.blackPaper = tempBlackpaer
            this.model.whitePaper = tempWhitePaper
            this.model.noticePhone = tempNoticePhone
            // this.model.isOpenPrivateOrder = !this.model.isOpenPrivateOrder ? 'no' : 'yes';
        },
        cancel() {
            this.visible = false;
            this.model = {
                blackPaper: [],
                whitePaper: [],
                noticePhone: []
            }
        },
        addList(listName) {
            console.log('listName', this.model[listName], this.model.noticePhone);
            let flag = false;
            for (let i = 0; i < this.model[listName].length; i++) {
                if (!this.model[listName][i].value) {
                    flag = true;
                    break;
                }
            }
            if (flag) {
                this.$message.warning('请先填写上一个内容');
            } else {
                this.model[listName].push({ value: '' });
            }
        },
        del(listName, index) {
            this.model[listName].splice(index, 1);
        },
        submitForm() {
            this.$refs.form.validate(async valid => {
                if (valid) {
                    let params = JSON.parse(JSON.stringify(this.model));
                    let tempBlackPaper = [];
                    params.blackPaper.forEach(item => {
                        tempBlackPaper.push(item.value);
                    })
                    let tempWhitePaper = [];
                    params.whitePaper.forEach(item => {
                        tempWhitePaper.push(item.value);
                    })
                    let TempNoticePhone = [];
                    params.noticePhone.forEach(item => {
                        TempNoticePhone.push(item.value);
                    })
                    params.blackPaper = tempBlackPaper.join(',');
                    params.whitePaper = tempWhitePaper.join(',');
                    params.noticePhone = TempNoticePhone.join(',');
                    console.log('params', params, params.realNameLogin);
                    // return;
                    let res = await postAction('hc/hcCompanyInfo/edit', params);
                    console.log('设置res', res);
                    if (res.success) {
                        this.$message.success('设置成功');
                        this.$emit('loadData');
                        this.cancel();
                    } else {
                        this.$message.wanring(res.message);
                    }
                }
            })
        },
    },
};
</script>

<style lang="scss" scoped></style>